package es.ats.codington.festival.junit;

import java.sql.Connection;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;


import es.ats.codington.festival.domain.Visitor;
import es.ats.codington.festival.services.VisitorService;
import junit.framework.TestCase;

public class TestVisitorService extends TestCase{
	
	Visitor visitor1;
	VisitorService vdi;
	Connection connection;
	boolean bool=true;
	
	
	@Before
	protected void setUp() throws Exception {
		super.setUp();
		
		visitor1 = new Visitor("Paco","Garcia","PacoGar@gmail.com",654321987,"calle amarilla","76428635J", "PacoG",
				"paquitor");
		vdi = new VisitorService();
		
	}
	
	@After
	protected void tearDown() throws Exception {
		super.tearDown();

	}
	
	
	@Test
	public void testVisitorServiceRegisterNewVisitor() {
		
		
		
		try {

			assertEquals(vdi.registerNewVisitor(visitor1),bool);
	
		} catch (Exception ex) {
			fail("No exception should be thrown");
		}
		
		
	}
	
	@Test
	public void testVisitorServiceUpdateVisitor() {
			
	
		try {
			visitor1 = new Visitor("Pepe","Leiva","Pepe@gmail.com",654321987,"calle amarilla","76428635J", "PacoG",
					"paquitor");
			visitor1.setIdVisitor(vdi.getIdVisitor(visitor1));
			
			assertEquals(vdi.updateVisitor(visitor1),bool);
	
		} catch (Exception ex) {
			fail("No exception should be thrown");
		}
		
		
	}
	
	@Test
	public void testLoginVisitor() {
		
			
		
		try {
			visitor1.setVisitorName("ALeiva");
			visitor1.setPassword("123456");
			
			assertEquals(vdi.login(visitor1),bool);
	
		} catch (Exception ex) {
			fail("No exception should be thrown");
		}
		
	}


	@Test
	public void testIsAdmin() {
		
		try {
			visitor1.setVisitorName("ALeiva");
			visitor1.setPassword("123456");
			assertTrue(vdi.isAdmin(visitor1));
			

		} catch (Exception ex) {
			fail("No exception should be thrown");
		}
		
	}
	@Test
	public void testUnregisterVisitor() {
		
		try {
			
			visitor1.setIdVisitor(vdi.getIdVisitor(visitor1));
			assertTrue(vdi.unregisterVisitor(visitor1));
			

		} catch (Exception ex) {
			fail("No exception should be thrown");
		}
		
	}
	
}